###############################################################################
# SuperLinks                                                                  #
# Copyright (c) 2000-2007 Greg Nolle (http://greg.nolle.co.uk)                #
###############################################################################
# This program is free software; you can redistribute it and/or modify it     #
# under the terms of the GNU General Public License as published by the Free  #
# Software Foundation; either version 2 of the License, or (at your option)   #
# any later version.                                                          #
#                                                                             #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       #
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for   #
# more details.                                                               ##                                                                             #
# You should have received a copy of the GNU General Public License along     #
# with this program; if not, write to the Free Software Foundation, Inc.,     #
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.                 #
###############################################################################
# Libraries/Templates/Form.pm -> Form template library                        #
###############################################################################
# DON'T EDIT BELOW UNLESS YOU KNOW WHAT YOU'RE DOING!                         #
###############################################################################
package Form;

BEGIN { require "System.pm.pl"; import System qw($SYSTEM); }
BEGIN { require "General.pm.pl"; import General qw($GENERAL); }

use HTML::Form;
use strict;

sub new {
  my ($class) = @_;
  my $self    = {};
  return bless ($self, $class);
}

sub DESTROY {}

###############################################################################
# TextBox subroutine
sub TextBox {
  my $self = shift;
  my %in = ("name" => "", "default" => "", "password" => 0, "class" => "form-textbox", "size" => "", (scalar(@_) == 1 ? %{ $_[0] } : @_));
  
  my $Form = HTML::Form->new();
  
  return $Form->TextBox(name => $in{'name'}, value => $in{'default'}, password => $in{'password'}, class => $in{'class'}, ($in{'size'} ? (extra => { size => $in{'size'} }) : ()));
}

###############################################################################
# FileBox subroutine
sub FileBox {
  my $self = shift;
  my %in = ("name" => "", "default" => "", "class" => "form-textbox", "size" => "", (scalar(@_) == 1 ? %{ $_[0] } : @_));
  
  my $Form = HTML::Form->new();
  
  return $Form->FileBox(name => $in{'name'}, value => $in{'default'}, class => $in{'class'}, ($in{'size'} ? (extra => { size => $in{'size'} }) : ()));
}

###############################################################################
# TextArea subroutine
sub TextArea {
  my $self = shift;
  my %in = ("name" => "", "default" => "", "rows" => 1, "class" => "form-textarea", (scalar(@_) == 1 ? %{ $_[0] } : @_));
  
  my $Form = HTML::Form->new();
  
  return $Form->TextArea(name => $in{'name'}, value => $in{'default'}, rows => $in{'rows'}, class => $in{'class'});
}

###############################################################################
# Radio subroutine
sub Radio {
  my $self = shift;
  my %in = ("name" => "", "default" => "", "value" => "", "label" => "", (scalar(@_) == 1 ? %{ $_[0] } : @_));
  
  my $Form = HTML::Form->new();
  
  return $Form->Radio(name => $in{'name'}, value => $in{'default'}, items => [{ value => $in{'value'}, label => $in{'label'} }]);
}

###############################################################################
# CheckBox subroutine
sub CheckBox {
  my $self = shift;
  my %in = ("name" => "", "default" => "", "value" => "", "label" => "", (scalar(@_) == 1 ? %{ $_[0] } : @_));
  
  my $Form = HTML::Form->new();
  
  return $Form->CheckBox(name => $in{'name'}, value => $in{'default'}, items => [{ value => $in{'value'}, label => $in{'label'} }]);
}

###############################################################################
# SelectBox subroutine
sub SelectBox {
  my $self = shift;
  my %in = ("name" => "", "default" => "", "items" => [], "rows" => 1, "multiple" => 0, "class" => "form-selectbox", (scalar(@_) == 1 ? %{ $_[0] } : @_));
  
  my $Form = HTML::Form->new();
  
  return $Form->SelectBox(name => $in{'name'}, value => $in{'default'}, items => $in{'items'}, rows => $in{'rows'}, multiple => $in{'multiple'}, class => $in{'class'});
}

###############################################################################
# Button subroutine
sub Button {
  my $self = shift;
  my %in = ("type" => "", "value" => "", "label" => "", "src" => "", "onClick" => "", (scalar(@_) == 1 ? %{ $_[0] } : @_));
  
  my $Form = HTML::Form->new();
  
  return $Form->Button(items => [{ type => $in{'type'}, value => $in{'value'}, label => $in{'label'}, src => $in{'src'}, ($in{'onClick'} ? (extra => { onClick => $in{'onClick'} }) : ()) }]);
}

###############################################################################
# StartForm subroutine
sub StartForm {
  my $self = shift;
  my %in = ("name" => "form", "method" => "POST", "action" => $SYSTEM->{'SCRIPT_URL'}, "multipart" => 0, (scalar(@_) == 1 ? %{ $_[0] } : @_));
  
  return $SL::CGI->start_form(
    -method   => $in{'method'},
    -action   => $in{'action'},
    -enctype  => ($in{'multipart'} ? "multipart/form-data" : ""),
    name      => $in{'name'}
  );
}

###############################################################################
# Hidden subroutine
sub Hidden {
  my $self = shift;
  my %in = ("name" => "", "value" => "", (scalar(@_) == 1 ? %{ $_[0] } : @_));
  
  return $SL::CGI->hidden(-name => $in{'name'}, -default => $in{'value'}, -override => 1);
}

###############################################################################
# EndForm subroutine
sub EndForm {
  my $self = shift;

  my $Return = $SL::CGI->endform();
  
  return $Return;
}

1;